#!/bin/bash

rm -rf out
# mod4
find ./mod4 -name "*.java" > sources.txt
javac -d out/mods/mod4 @sources.txt -Xlint:none
jar -cvf out/mods/mod4.jar -C out/mods/mod4 .

# mod3
find ./mod3 -name "*.java" > sources.txt
javac -d out/mods/mod3 @sources.txt -Xlint:none
jar -cvf out/mods/mod3.jar -C out/mods/mod3 .

# mod2b
find ./mod2b -name "*.java" > sources.txt
javac -p out/mods/mod3.jar -d out/mods/mod2b @sources.txt -Xlint:none
jar -cvf out/mods/mod2b.jar -C out/mods/mod2b .

# mod2a
find ./mod2a -name "*.java" > sources.txt
javac -p out/mods/mod3.jar -d out/mods/mod2a @sources.txt -Xlint:none
jar -cvf out/mods/mod2a.jar -C out/mods/mod2a .

# mod1
find ./mod1 -name "*.java" > sources.txt
javac -p out/mods/mod2a.jar:out/mods/mod2b.jar:out/mods/mod3.jar:out/mods/mod4.jar -d out/mods/mod1 @sources.txt -Xlint:none
jar -cvf out/mods/mod1.jar -C out/mods/mod1 .

# run
java -p out/mods/mod1.jar:out/mods/mod2a.jar:out/mods/mod2b.jar:out/mods/mod3.jar:out/mods/mod4.jar -m mod1/mod1.EventCenter -Xlint:none
